package com.example.springbootlearn.listener;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.event.ApplicationContextEvent;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;

/**
 * @author caiji Mr. Li
 * @date 2019/10/28 18:32
 */
public class AnnotationEventListenerBootStrap {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.registerBean(MymutiEventListener.class);
        context.refresh();
        context.close();

    }

    public static class MymutiEventListener {

        @EventListener({ContextRefreshedEvent.class, ContextClosedEvent.class})
        public void onEvent() {
            System.out.println("onEvent");
        }

        @EventListener({ContextRefreshedEvent.class, ContextClosedEvent.class})
        public void onApplicationContextEvent(ApplicationContextEvent event) {
            System.out.println("onApplicationContextEvent : " + event.getClass().getSimpleName());
        }

//        @EventListener({ContextRefreshedEvent.class, ContextClosedEvent.class})
        public void onEvents(ContextRefreshedEvent refreshedEvent, ContextClosedEvent contextClosedEvent) {
            System.out.println("onEvents : " + refreshedEvent.getClass().getSimpleName()
                    + " , " + contextClosedEvent.getClass().getSimpleName());
        }
    }
}
